<template>
  <div>
    <!-- 查询参数及按钮部分 -->
    <el-dialog  v-dialogDrag  
      :title="dialogStatus"
      :visible.sync="dialogEditFormVisible"
      style="padding:0px"
    >
      <el-form
        ref="dataForm"
        class="dialog-Backgroundcolor"
        :model="listQuery"
        label-position="right"
        label-width="100px"
      >

        <!--            <el-col :span="12">-->
        <!--              <el-form-item label="有无变动">-->
        <!--                <el-select-->
        <!--                  v-model="listQuery.changesType"-->
        <!--                  class="filter-item"-->
        <!--                  clearable-->
        <!--                  placeholder="&#45;&#45;请选择&#45;&#45;"-->
        <!--                >-->
        <!--                  <el-option-->
        <!--                    label="有变动"-->
        <!--                    value="1"-->
        <!--                  />-->
        <!--                  <el-option-->
        <!--                    label="无变动"-->
        <!--                    value="0"-->
        <!--                  />-->
        <!--                </el-select>-->
        <!--              </el-form-item>-->
        <!--            </el-col>-->
        <el-row>
          <el-col :span="12">
            <el-form-item label="人员类型">
              <el-select
                v-model="listQuery.personType"
                class="filter-item"
                clearable
                placeholder="--请选择--"
              >
                <el-option
                  label="在职人员"
                  value="3"
                />
                <el-option
                  label="离退休人员"
                  value="1"
                />
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="工资类型">
              <el-select
                v-model="listQuery.salaryType"
                class="filter-item"
                clearable
                placeholder="--请选择--"
              >
                <el-option
                  label="行政人员"
                  value="0"
                />
                <el-option
                  label="事业人员"
                  value="1"
                />
                <el-option
                  label="离退休人员"
                  value="11"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="单位名称">
              <el-input
                v-model="listQuery.dwmc"
                class="filter-item Borderwidth"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-button
              type="primary"
              style="float:right;margin-top:10px"
              @click="handleQuery"
            >
              查询
            </el-button>
          </el-col>

        </el-row>

      </el-form>
    </el-dialog>

    <!-- 表格部分 -->
    <el-table
      ref="singalTable"
      v-loading="listLoading"
      :data="list"
      :stripe="true"
      fit
      :height="tableHeight"

      max-height="455px"
      :header-cell-style="{background:'#eef1f6',color:'#606266'}"
    >
      <template slot="empty">
        <tableEmpty />
      </template>
      <el-table-column
        label="单位名称"
        align="center"
      >
        <template slot-scope="{row}">
          <span style="float: left">{{ row.agencyName }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="工资月份"
        align="center"
      >
        <template slot-scope="{row}">
          <span>{{ row.salaryMonth }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="实发工资总额"
        align="center"
      >
        <template slot-scope="{row}">
          <!--Number(row.theActualTotalWages).toFixed(2)把获取来的数据转换成数字保留两位小数  -->
          <span style="float: right">{{
            Number(row.theActualTotalWages).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, '$1,')
          }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="应发工资总额"
        align="center"
      >
        <template slot-scope="{row}">
          <span style="float: right">{{
            Number(row.shouldIssueTotalWages).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, '$1,')
          }}</span>
        </template>
      </el-table-column>

      <el-table-column
        label="备注"
        align="center"
      >
        <!-- <template slot-scope="{row}">
            <span>{{ row.agencyBankName | bankFilters(that) }}</span>
          </template> -->
      </el-table-column>
    </el-table>
    <pagination
      :total="total"
      :page.sync="listQuery.page"
      :limit.sync="listQuery.limit"
      @pagination="getList"
    />
  </div>
</template>
<script>
import { getunitSubmitSituationQueryList } from '@/api/salaryReport/unitSubmitSituationQuery'
// 引入分页控件
import Pagination from '@/components/Pagination' // secondary package based on el-pagination
import tableEmpty from '@/components/table/empty'

export default {
  name: 'Unit',
  components: { Pagination, tableEmpty },
  props: ['tabPane'],
  data() {
    return {
      tableHeight: null,
      dialogStatus: '',
      treeShow: true,
      that: this,
      list: null,
      total: 0,
      listLoading: true,
      dialogEditFormVisible: false,
      listQuery: {
        page: 1,
        limit: 200,
        changesType: '',
        personType: '',
        salaryType: '',
        agencyName: '',

        month: new Date(),
        flag: '0',
        // this.$store.getters.userInfo.agencyId那个人登录就显示那个人的agencyId
        agencyId: this.$store.getters.userInfo.agencyId,
        newId: ''
        // num: '0'
      }
    }
  },
  watch: {
    list(val) {
      this.doLayout()
    }
  },
  created() {
    this.listQuery.flag = this.tabPane
    this.getList()
  },
  mounted() {
    this.getTbHeight()
  },
  beforeMount() {
    window.addEventListener('resize', this.getTbHeight)
  },
  methods: {

    /* 重新渲染table组件 */
    doLayout() {
      this.$nextTick(() => {
        this.$refs.singalTable.doLayout()
      })
    },
    // 获取table高度的方法
    getTbHeight() {
      this.tableHeight = window.innerHeight + 200
    },
    getList() {
      this.listLoading = true
      // 获取table数据，分页unitSubmitSituationQuery
      getunitSubmitSituationQueryList(this.listQuery).then(response => {
        this.list = response.data.rows
        this.total = response.data.total
        // 当数据查询出来以后不在转圈
        this.listLoading = false
      })
    },
    // 树的点击事件
    handleTree(data) {
      this.listQuery.newId = data.id
      this.getList()
    },
    // 查询
    query() {
      this.dialogStatus = '查询'
      this.dialogEditFormVisible = true
    },
    // 切换树是否显示
    toggerTree() {
      this.treeShow = !this.treeShow
    },
    // 查询按钮功能
    handleQuery() {
      this.listQuery.page = 1
      // 然后走这个方法
      this.getList()
      this.dialogEditFormVisible = false
    }
  }
}
</script>

